﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            商业信息管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2011-7-28 16:36:37
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BingZi.HY.Core.Entities.Center;
using BingZi.HY.Core.Message;
using BingZi.HY.Core.WebControls;
using BingZi.HY.Core.Enums;
using BingZi.HY.Core;





namespace BingZi.HY.UI.Center.Manager.app_BusinessInfoUI
{
    public partial class Manager : BingZi.HY.Core.BLL.PageBase
    {
        Int32 IDX = (Int32)BingZi.HY.Core.Common.sink("IDX", BingZi.HY.Core.Enums.MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)BingZi.HY.Core.Common.sink("CMD", BingZi.HY.Core.Enums.MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            app_BusinessInfo ut = app_BusinessInfo.FindByKeyForEdit(IDX);
            OnStartData(ut);
            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加商业信息";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看商业信息";
                    Hidden_Input();
                    ButtonOption.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改商业信息";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    
                    if(ut.Delete() > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Edit;
            bi.ButtonName = "商业信息";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Delete;
            bi.ButtonName = "商业信息";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(app_BusinessInfo ut)
        {
        b_Title_Input.Text = b_Title_Disp.Text = ut.b_Title.ToString();
                b_InfoType_Input.Text = b_InfoType_Disp.Text = ut.b_InfoType.ToString();
                b_Tags_Input.Text = b_Tags_Disp.Text = ut.b_Tags.ToString();
                b_Category_Input.Text = b_Category_Disp.Text = ut.b_Category.ToString();
                b_CategoryText_Input.Text = b_CategoryText_Disp.Text = ut.b_CategoryText.ToString();
                b_ShopCategory_Input.Text = b_ShopCategory_Disp.Text = ut.b_ShopCategory.ToString();
                b_UserID_Input.Text = b_UserID_Disp.Text = ut.b_UserID.ToString();
                b_UserName_Input.Text = b_UserName_Disp.Text = ut.b_UserName.ToString();
                b_CompanyName_Input.Text = b_CompanyName_Disp.Text = ut.b_CompanyName.ToString();
                b_AreaIds_Input.Text = b_AreaIds_Disp.Text = ut.b_AreaIds.ToString();
                b_AreaNames_Input.Text = b_AreaNames_Disp.Text = ut.b_AreaNames.ToString();
                b_Attribute_Input.Text = b_Attribute_Disp.Text = ut.b_Attribute.ToString();
                b_EffectTime_Input.Text = b_EffectTime_Disp.Text = ut.b_EffectTime.ToString();
                b_StartTime_Input.Text = b_StartTime_Disp.Text = ut.b_StartTime.ToString();
                b_UpdateTime_Input.Text = b_UpdateTime_Disp.Text = ut.b_UpdateTime.ToString();
                b_Balance_Input.Text = b_Balance_Disp.Text = ut.b_Balance.ToString();
                b_Content_Input.Text = b_Content_Disp.Text = ut.b_Content.ToString();
                b_InfoPhoto_Input.Text = b_InfoPhoto_Disp.Text = ut.b_InfoPhoto.ToString();
                b_Unit_Input.Text = b_Unit_Disp.Text = ut.b_Unit.ToString();
                b_Price_Input.Text = b_Price_Disp.Text = ut.b_Price.ToString();
                b_MaxUnit_Input.Text = b_MaxUnit_Disp.Text = ut.b_MaxUnit.ToString();
                b_MinUnit_Input.Text = b_MinUnit_Disp.Text = ut.b_MinUnit.ToString();
                b_State_Input.Text = b_State_Disp.Text = ut.b_State.ToString();
                
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
        b_Title_Input.Visible = false;
        b_InfoType_Input.Visible = false;
        b_Tags_Input.Visible = false;
        b_Category_Input.Visible = false;
        b_CategoryText_Input.Visible = false;
        b_ShopCategory_Input.Visible = false;
        b_UserID_Input.Visible = false;
        b_UserName_Input.Visible = false;
        b_CompanyName_Input.Visible = false;
        b_AreaIds_Input.Visible = false;
        b_AreaNames_Input.Visible = false;
        b_Attribute_Input.Visible = false;
        b_EffectTime_Input.Visible = false;
        b_StartTime_Input.Visible = false;
        b_UpdateTime_Input.Visible = false;
        b_Balance_Input.Visible = false;
        b_Content_Input.Visible = false;
        b_InfoPhoto_Input.Visible = false;
        b_Unit_Input.Visible = false;
        b_Price_Input.Visible = false;
        b_MaxUnit_Input.Visible = false;
        b_MinUnit_Input.Visible = false;
        b_State_Input.Visible = false;
        
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
        b_Title_Disp.Visible = false;
        b_InfoType_Disp.Visible = false;
        b_Tags_Disp.Visible = false;
        b_Category_Disp.Visible = false;
        b_CategoryText_Disp.Visible = false;
        b_ShopCategory_Disp.Visible = false;
        b_UserID_Disp.Visible = false;
        b_UserName_Disp.Visible = false;
        b_CompanyName_Disp.Visible = false;
        b_AreaIds_Disp.Visible = false;
        b_AreaNames_Disp.Visible = false;
        b_Attribute_Disp.Visible = false;
        b_EffectTime_Disp.Visible = false;
        b_StartTime_Disp.Visible = false;
        b_UpdateTime_Disp.Visible = false;
        b_Balance_Disp.Visible = false;
        b_Content_Disp.Visible = false;
        b_InfoPhoto_Disp.Visible = false;
        b_Unit_Disp.Visible = false;
        b_Price_Disp.Visible = false;
        b_MaxUnit_Disp.Visible = false;
        b_MinUnit_Disp.Visible = false;
        b_State_Disp.Visible = false;
        
        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            string b_Title_Value = (string)BingZi.HY.Core.Common.sink(b_Title_Input.UniqueID, MethodType.Post, 100, 1, DataType.Str);
            int b_InfoType_Value = (int)BingZi.HY.Core.Common.sink(b_InfoType_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            string b_Tags_Value = (string)BingZi.HY.Core.Common.sink(b_Tags_Input.UniqueID, MethodType.Post, 100, 0, DataType.Str);
            int b_Category_Value = (int)BingZi.HY.Core.Common.sink(b_Category_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            string b_CategoryText_Value = (string)BingZi.HY.Core.Common.sink(b_CategoryText_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            int b_ShopCategory_Value = (int)BingZi.HY.Core.Common.sink(b_ShopCategory_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int b_UserID_Value = (int)BingZi.HY.Core.Common.sink(b_UserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            string b_UserName_Value = (string)BingZi.HY.Core.Common.sink(b_UserName_Input.UniqueID, MethodType.Post, 20, 1, DataType.Str);
            string b_CompanyName_Value = (string)BingZi.HY.Core.Common.sink(b_CompanyName_Input.UniqueID, MethodType.Post, 100, 1, DataType.Str);
            string b_AreaIds_Value = (string)BingZi.HY.Core.Common.sink(b_AreaIds_Input.UniqueID, MethodType.Post, 20, 1, DataType.Str);
            string b_AreaNames_Value = (string)BingZi.HY.Core.Common.sink(b_AreaNames_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            
            int b_EffectTime_Value = (int)BingZi.HY.Core.Common.sink(b_EffectTime_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            DateTime b_StartTime_Value = (DateTime)BingZi.HY.Core.Common.sink(b_StartTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            DateTime b_UpdateTime_Value = (DateTime)BingZi.HY.Core.Common.sink(b_UpdateTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            double b_Balance_Value = (double)BingZi.HY.Core.Common.sink(b_Balance_Input.UniqueID, MethodType.Post, 53, 1, DataType.Double);
            string b_Content_Value = (string)BingZi.HY.Core.Common.sink(b_Content_Input.UniqueID, MethodType.Post, 2147483647, 1, DataType.Str);
            string b_InfoPhoto_Value = (string)BingZi.HY.Core.Common.sink(b_InfoPhoto_Input.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            string b_Unit_Value = (string)BingZi.HY.Core.Common.sink(b_Unit_Input.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            double b_Price_Value = (double)BingZi.HY.Core.Common.sink(b_Price_Input.UniqueID, MethodType.Post, 53, 0, DataType.Double);
            string b_MaxUnit_Value = (string)BingZi.HY.Core.Common.sink(b_MaxUnit_Input.UniqueID, MethodType.Post, 10, 0, DataType.Str);
            string b_MinUnit_Value = (string)BingZi.HY.Core.Common.sink(b_MinUnit_Input.UniqueID, MethodType.Post, 10, 0, DataType.Str);
            int b_State_Value = (int)BingZi.HY.Core.Common.sink(b_State_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            app_BusinessInfo ut = app_BusinessInfo.FindByKeyForEdit(IDX);
            
            ut.b_Title = b_Title_Value;
            ut.b_InfoType = b_InfoType_Value;
            ut.b_Tags = b_Tags_Value;
            ut.b_Category = b_Category_Value;
            ut.b_CategoryText = b_CategoryText_Value;
            ut.b_ShopCategory = b_ShopCategory_Value;
            ut.b_UserID = b_UserID_Value;
            ut.b_UserName = b_UserName_Value;
            ut.b_CompanyName = b_CompanyName_Value;
            ut.b_AreaIds = b_AreaIds_Value;
            ut.b_AreaNames = b_AreaNames_Value;
           // ut.b_Attribute = b_Attribute_Value;
            ut.b_EffectTime = b_EffectTime_Value;
            ut.b_StartTime = b_StartTime_Value;
            ut.b_UpdateTime = b_UpdateTime_Value;
            ut.b_Balance = b_Balance_Value;
            ut.b_Content = b_Content_Value;
            ut.b_InfoPhoto = b_InfoPhoto_Value;
            ut.b_Unit = b_Unit_Value;
            ut.b_Price = b_Price_Value;
            ut.b_MaxUnit = b_MaxUnit_Value;
            ut.b_MinUnit = b_MinUnit_Value;
            ut.b_State = b_State_Value;
            
            Int32 rInt =0; if (CMD == "New")
            {
                rInt = ut.Insert();
            }
            else if (CMD == "Edit")
            {
                rInt = ut.Update();
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            
            if ( rInt> 0)
            {
                string OpTxt = string.Format("增加商业信息成功!(ID:{0})", rInt);
                if(CMD == "Edit")
                    OpTxt = string.Format("修改商业信息成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
